/**
 * 流线实验 列表页
 *
 * 作者 ganjun
 * 日期 2024-12-11 00:38:15
 */
layui.use(['jquery', 'laydate', 'febs', 'form', 'table', 'commonJS', 'validate'], function () {
    var $ = layui.jquery,
        laydate = layui.laydate,
        febs = layui.febs,
        form = layui.form,
        table = layui.table,
        commonJS = layui.commonJS,
        validate = layui.validate,
        $view = $('#febs-taskTestlx'),
        $query = $view.find('#query'),
        $searchForm = $view.find('#taskTestlx-table-form'),
        tableIns;

    form.verify(validate);
    form.render();

    initTable();

    function initTable() {
        tableIns = febs.table.init({
            elem: $view.find('table'),
            id: 'taskTestlxTable',
            url: ctx + 'taskTestlx/list',
            where: getQueryParams(),
            height: getTableHeight(),
            skin: '',
            cols: [[
                {type: 'checkbox'},
                {field: 'shipcode', title: '船模编号', minWidth: 120},
                {field: 'draugh', title: '吃水mm', minWidth: 120},
                {field: 'displacement', title: '排水ml', minWidth: 120},
                {field: 'speed', title: '船模速度（m/s）', minWidth: 120},
                {field: 'remark', title: '备注', minWidth: 120},
                {field: 'id', title: '', minWidth: 120},
            ]],
            toolbar: '#taskTestlx-toolbar',
            defaultToolbar: []
        });
    }

    table.on('sort(taskTestlxTable)', function (obj) {
        tableIns.reload({
            initSort: obj,
            where: $.extend(getQueryParams(), {
                field: obj.field,
                order: obj.type
            }),
            autoSort: true
        });
    });

    function reloadPage(curr) {
        var _curr = $view.find(".layui-laypage-em").next().html();
        if (!!curr) {
            _curr = curr;
        }
        tableIns.reload({where: getQueryParams(), page: {curr: _curr}});
    }

    $query.on('click', function () {
        reloadPage(1);
    });

    table.on('toolbar(taskTestlxTable)', function (obj) {
        if (obj.event === 'add') {
            febs.modal.open('新增', 'taskTestlx/add', {
                btn: ['提交', '取消'],
                area: [$(window).width() <= 750 ? '95%':'50','800px'],
                yes: function (index, layero) {
                    $('#taskTestlx-edit').find('#submit').trigger('click');
                },
                btn2: function () {
                    layer.closeAll();
                },
                data: {

                }
            });
        }
    });

    table.on('tool(taskTestlxTable)', function (obj) {
        var data = obj.data,
        layEvent = obj.event;
        if (layEvent === 'edit') {
            febs.modal.open('修改', 'taskTestlx/update/' + data, {
                area: [$(window).width() <= 750 ? '95%':'50','800px'],
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                    $('#taskTestlx-edit').find('#submit').trigger('click');
                },
                btn2: function () {
                    layer.closeAll();
                },
                data: {

                },
            });
        }
    });



    function getQueryParams() {
        return {
            name: $searchForm.find('input[name="name"]').val().trim(),
            invalidate_ie_cache: new Date()
        };
    }


    function getTableHeight() {
        return commonJS.calcTableHeight();
    }

    $(window).resize(function () {
        tableIns.reload({height: getTableHeight()});
    });

});